package com.sptpc.demo.controller;


import com.sptpc.demo.model.Category;
import com.sptpc.demo.model.Drink;
import com.sptpc.demo.service.ICategoryService;
import com.sptpc.demo.service.IDrinkService;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RouterController {
    @Autowired
public IDrinkService drinkService;
    @Autowired
    public ICategoryService categoryService;
    //首页登陆路由
    @GetMapping("/")
    public String Index(){

        return "manage/login";
    }
    //后台首页路由
    @GetMapping("/manage/index")
    public String adminIndex(){

        return "manage/index";
    }
    //后台欢迎页面路由
    @GetMapping("/manage/welcome")
    public String welcome(){

        return "manage/welcome";
    }
    //饮品管理首页路由
    @GetMapping("/menu/drink")
    public String drinkIndex(){

        return "drink/index";
    }
    //饮品添加路由
    @GetMapping("/drink/addform")
    public String drinkAddIndex(){

        return "drink/add";
    }
    //饮品修改页路由
    // get /drink/updateform?id=13
    @GetMapping("/drink/updateform")
    public ModelAndView drinkUpdateForm(@RequestParam Integer id){
        ModelAndView mv=new ModelAndView("drink/edit");
        //TODO: 从数据库通过id查询出对应的饮品信息
       Drink drink=drinkService.getDrinkById(id);
       mv.addObject("data",drink);
        return mv;
    }

    //分类管理首页路由
    @GetMapping("/menu/category")
    public String categoryIndex(){

        return "category/index";
    }
    //分类添加路由
    @GetMapping("/category/addform")
    public String categoryAddIndex(){

        return "category/add";
    }

    //get /category/updateform?id=
    @GetMapping("/category/updateform")
    public ModelAndView categoryUpdateForm(@RequestParam Integer id){
        ModelAndView mv=new ModelAndView("category/edit");
        Category category= categoryService.getCategoryById(id);
        mv.addObject("data",category);
        return mv;
    }


}
